home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kommanderwidget.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-02-13  |  6.9 KB  |  163 lines

  1. /***************************************************************************
  2.                     kommanderwidget.h - Text widget core functionality 
  3.                              -------------------
  4.     copyright          : (C) 2002-2003 Marc Britton <consume@optusnet.com.au>
  5.                          (C) 2004      Michal Rudolf <mrudolf@kdewebdwev.org>
  6.     
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #ifndef _HAVE_KOMMANDERWIDGET_H_
  19. #define _HAVE_KOMMANDERWIDGET_H_
  20.  
  21. /* KDE INCLUDES */
  22. #include <kprocess.h>
  23.  
  24. #include "kommander_export.h"
  25. /* QT INCLUDES */
  26. #include <qmap.h>
  27. #include <qobject.h>
  28. #include <qpair.h>
  29. #include <qstring.h>
  30. #include <qstringlist.h>
  31.  
  32. class ParserData;
  33.  
  34. class KOMMANDER_EXPORT KommanderWidget
  35. {
  36.   friend class MyProcess;
  37. public:
  38.   KommanderWidget(QObject *);
  39.   virtual ~KommanderWidget();
  40.  
  41.   //List of available states. Most widgets have only one state, but f. e. radiobutton has both 
  42.   // 'checked' and 'unchecked'
  43.   virtual QStringList states() const;
  44.   virtual QStringList displayStates() const;
  45.   virtual QString currentState() const = 0;
  46.  
  47.   virtual bool isKommanderWidget() const = 0;
  48.  
  49.   // Associated script
  50.   virtual void setAssociatedText(const QStringList& a_associations);
  51.   virtual QStringList associatedText() const;
  52.   virtual bool hasAssociatedText();
  53.  
  54.   // Execute default script, expanding all @macros.
  55.   virtual QString evalAssociatedText();
  56.   // Execute given script, expanding all @macros.
  57.   virtual QString evalAssociatedText(const QString&);
  58.   // Evaluate given Kommander function using given args.
  59.   virtual QString evalFunction(const QString& function, const QStringList& args);
  60.   // Parse and evaluate function for given widget, converting it to appropriate DCOP call.
  61.   virtual QString evalWidgetFunction(const QString& identifier, const QString& s, int& pos);
  62.   // Evaluate given array function using given args.
  63.   virtual QString evalArrayFunction(const QString&, const QStringList&);
  64.   // Parse and evaluate given execBegin..execEnd block.
  65.   virtual QString evalExecBlock(const QStringList&, const QString& s, int& pos);
  66.   // Parse and evaluate given forEach..end block.
  67.   virtual QString evalForEachBlock(const QStringList&, const QString& s, int& pos);
  68.   // Parse and evaluate given for..end block.
  69.   virtual QString evalForBlock(const QStringList&, const QString& s, int& pos);
  70.   // Parse and evaluate given switch..case..end block.
  71.   virtual QString evalSwitchBlock(const QStringList&, const QString& s, int& pos);
  72.   // Parse and evaluate given if..endif block.
  73.   virtual QString evalIfBlock(const QStringList&, const QString& s, int& pos);
  74.   // Population text. It will become widgetText after populate() is called
  75.   virtual QString populationText() const;
  76.   virtual void setPopulationText(const QString&);
  77.   virtual void populate() = 0;
  78.  
  79.   // Handles all widget-specific DCOP calls 
  80.   virtual QString handleDCOP(int function, const QStringList& args = QStringList());
  81.   // Checks if appropriate function is supported by widget. By default all functions
  82.   // are reported as supported: use this to allow recognizing incorrect function calls.
  83.   virtual bool isFunctionSupported(int function);
  84.   // Checks if the function is common widget function (i. e. supported by all widgets)
  85.   virtual bool isCommonFunction(int function);
  86.   // Checks if the string is a valid widget name)
  87.   virtual bool isWidget(const QString& a_name) const;
  88.   // Returns widget from name 
  89.   virtual KommanderWidget* widgetByName(const QString& a_name) const;
  90.   // Returns current widget name;
  91.   virtual QString widgetName() const;
  92.   // Returns filename associated with the dialog
  93.   virtual QString fileName();
  94.  
  95.   QObject* object() { return m_thisObject;}
  96.  
  97.  
  98.   // Recognizes editor vs executor mode
  99.   static bool inEditor;
  100.   // Prints errors in message boxes, not in stderr
  101.   static bool showErrors;
  102.   // Default parser
  103.   static bool useInternalParser;
  104.   // Return global variable value
  105.   QString global(const QString& variableName);
  106.   // Set global variable value
  107.   void setGlobal(const QString& variableName, const QString& value);
  108.  
  109. protected:
  110.   virtual void setStates(const QStringList& a_states);
  111.   virtual void setDisplayStates(const QStringList& a_displayStates);
  112.  
  113.   // Execute DCOP query and return its result or null on failure
  114.   // Only QString and int are now handled
  115.   QString DCOPQuery(const QStringList& args);
  116.   QString localDCOPQuery(const QString function, const QStringList& args = QStringList());
  117.   QString localDCOPQuery(const QString function, const QString& arg1, 
  118.      const QString& arg2, const QString& arg3 = QString::null,
  119.      const QString& arg4 = QString::null);
  120.   // Execute given command, return its result
  121.   QString execCommand(const QString& a_command, const QString& a_shell = QString::null) const;
  122.   // Find and run dialog (with optional parameters)
  123.   QString runDialog(const QString& a_dialog, const QString& a_params = QString::null);
  124.   // Display error message a_error; display current class name if no other is given
  125.   void printError(const QString& a_error) const;
  126.   // Auxiliary functions for parser
  127.   // Find matching brackets starting from current position
  128.   QString parseBrackets(const QString& s, int& from, bool& ok) const;
  129.   // Return identifier: the longest string of letters and numbers starting from i
  130.   QString parseIdentifier(const QString& s, int& from) const;
  131.   // Parse arguments for given function. Returns list of arguments without quotations
  132.   QStringList parseArgs(const QString& s, bool &ok);
  133.   // Remove quotes from given identifier
  134.   QString parseQuotes(const QString& s) const;
  135.   // Parse function
  136.   QStringList parseFunction(const QString& group, const QString& function,
  137.     const QString& s, int& from, bool& ok);
  138.   // Detect and return block boundary
  139.   int parseBlockBoundary(const QString& s, int from, const QStringList& args) const;
  140.  
  141.   // Parse given identifier as widget name
  142.   KommanderWidget* parseWidget(const QString& name) const;
  143.   // Return parent dialog of this widget
  144.   QWidget* parentDialog() const;
  145.   QString substituteVariable(QString text, QString variable, QString value) const;
  146.  
  147.   ParserData* internalParserData() const;
  148.  
  149.   QObject *m_thisObject;
  150.   QStringList m_states;
  151.   QStringList m_displayStates;
  152.   QStringList m_associatedText;
  153.   QString m_populationText;
  154.  
  155.   // Internal parser data
  156.   static ParserData* m_parserData;
  157. };
  158.  
  159.  
  160. #define ESCCHAR '@'
  161.  
  162. #endif
  163.